package chapter18;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

public class OSExecute {
	public static void command(String command)
	{
		try
		{
			Process process=new ProcessBuilder(command.split(" ")).start();
			BufferedReader results=new BufferedReader(new InputStreamReader(process.getInputStream()));
			String s;
			while((s=results.readLine())!=null)System.out.println(s);
			BufferedReader errors=new BufferedReader(new InputStreamReader(process.getErrorStream()));
			while((s=errors.readLine())!=null)System.out.println(s);
		}catch(Exception e)
		{
			System.out.println(e.getMessage());
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		command("java chapter18/DirList.java");

	}

}
